home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / mmdf / mmdf-IIb.43 / src / tools / amp.c next >
Encoding:
C/C++ Source or Header  |  1989-05-11  |  2.1 KB  |  83 lines

  1. /*
  2.  * This program acts as a filter which reformats message headers.
  3.  * Normally the standard input is copied to the standard output,
  4.  * with errors indicated by non-zero exit status.
  5.  *    Arguments can be given, with the following meanings:
  6.  *        % amp <channame> <output file> <top debug> <low debug>
  7.  *    The 1st argument if present is taken to be a channel name
  8.  *        to normalize with respect to.  If this is -, the
  9.  *        NULL channel will be used.
  10.  *    The 2nd argument if present specifies output file to use
  11.  *        instead of standard output; useful when debugging.
  12.  *        "-" will get std output anyway.
  13.  *    A 3rd argument, if present, turns on top-level debug output,
  14.  *        which always goes to the std output.
  15.  *    A 4th argument, if present, turns on low-level debug output.
  16.  *
  17.  *    Hacked 12Mar81 by KLH @ SRI.  Uses Dave Crocker's RFC733
  18.  *    address parsing package.  No warranty, express or implied,
  19.  *    shall apply to this horrible kludge.
  20.  */
  21.  
  22. #include <stdio.h>
  23. #include "util.h"
  24. #include "mmdf.h"
  25. #include "ch.h"
  26. #include "ap.h"
  27.  
  28. #if DEBUG > 1
  29. extern    int    tdebug;            /* Top-level debug flag */
  30. extern    int    debug;            /* Low-level debug flag */
  31. #endif
  32.  
  33. extern    LLog    *logptr;
  34. extern    Chan    *ch_nm2struct();
  35. extern    long    amp_hdr();
  36. extern    int    ap_outtype;
  37.  
  38. /* */
  39.  
  40. main(argc, argv)
  41. int argc;
  42. char *argv[];
  43. {
  44.     register    int    c;
  45.             FILE    *outf;
  46.             Chan    *chanptr;
  47.             long    offset;
  48.             int    ofd;
  49.  
  50.     mmdf_init(argv[0]);
  51.  
  52.     if (argc < 2 || (chanptr = ch_nm2struct(argv[1])) == (Chan *)NOTOK) {
  53.         chanptr = (Chan *)NULL;
  54.         ap_outtype = AP_822;
  55.     } else
  56.         ap_outtype = chanptr->ch_apout;
  57.  
  58.     if (argc < 3 || (argv[2][0] == '-' && argv[2][1] == '\0')
  59.         || ((ofd = creat("amp.out", 0400)) < 0))
  60.         outf = stdout;        /* Output to std output */
  61.     else
  62.         outf = fdopen(ofd, "w");
  63.  
  64. #if DEBUG > 1
  65.     if (argc >= 4)
  66.         tdebug++;        /* Top-level debugging */
  67.     if (argc == 5)
  68.         debug++;        /* Low-level debugging */
  69. #endif
  70.     if (argc == 5)
  71.         logptr->ll_level = LLOGFTR;
  72.  
  73.     offset = amp_hdr(chanptr, stdin, outf);
  74.     if (offset == NOTOK || offset == MAYBE) {
  75.         fprintf(stderr, "\nReformat failed.\n");
  76.         exit (-1);
  77.     }
  78.     /* Reformat succeeded, Copy message text */
  79.     while ((c = getchar()) != EOF)
  80.         putc(c, outf);
  81.     exit(0);
  82. }
  83.